package com.ruoyi.web.controller.system;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Safeguard;
import com.ruoyi.system.service.ISafeguardService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 平台保障服务Controller
 *
 * @author ruoyi
 * @date 2021-05-19
 */
@RestController
@RequestMapping("/super/safeguard")
public class SafeguardController extends BaseController
{
    @Autowired
    private ISafeguardService safeguardService;

    /**
     * 查询平台保障服务列表
     */

    @GetMapping("/list")
    public TableDataInfo list(Safeguard safeguard)
    {
        startPage();
        List<Safeguard> list = safeguardService.selectSafeguardList(safeguard);
        return getDataTable(list);
    }

    /**
     * 导出平台保障服务列表
     */

    @GetMapping("/export")
    public AjaxResult export(Safeguard safeguard)
    {
        List<Safeguard> list = safeguardService.selectSafeguardList(safeguard);
        ExcelUtil<Safeguard> util = new ExcelUtil<Safeguard>(Safeguard.class);
        return util.exportExcel(list, "safeguard");
    }

    /**
     * 获取平台保障服务详细信息
     */

    @GetMapping(value = "/{safeguardId}")
    public AjaxResult getInfo(@PathVariable("safeguardId") Long safeguardId)
    {
        return AjaxResult.success(safeguardService.selectSafeguardById(safeguardId));
    }

    /**
     * 新增平台保障服务
     */
    @PostMapping
    public AjaxResult add(@RequestBody Safeguard safeguard)
    {
        return toAjax(safeguardService.insertSafeguard(safeguard));
    }

    /**
     * 修改平台保障服务
     */

    @PutMapping
    public AjaxResult edit(@RequestBody Safeguard safeguard)
    {
        return toAjax(safeguardService.updateSafeguard(safeguard));
    }

    /**
     * 删除平台保障服务
     */

    @DeleteMapping("/{safeguardIds}")
    public AjaxResult remove(@PathVariable Long[] safeguardIds)
    {
        return toAjax(safeguardService.deleteSafeguardByIds(safeguardIds));
    }
}